<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    {include file="/layout/scriptload"}
    <title>添加关键词回复</title>
</head>
<body>
<div class="box">
    <!-- /.box-header -->
    <section class="content">
    <div class="box-body">
        <form role="form">
            <div class="form-group col-md-7">
                <label>所属一级分类</label>
                <select id="category" class="form-control">
                    <option value="">请选择...</option>
                    {volist name="category" id='vo'}
                        <option value="{$vo.id}">{$vo.categoryname}</option>
                    {/volist}
                </select>
            </div>
            <div class="form-group col-md-7">
                <label>所属二级分类</label>
                <select id="category2" class="form-control">
                    <option value="">请选择...</option>
                </select>
            </div>
            <div class="form-group col-md-7" >
                <label>标题</label>
                <input type="text" id="title" class="form-control"  placeholder="请输入标题...">
            </div>
            <div class="form-group col-md-7">
                <label>内容</label>
                <input type="text" id="desc" class="form-control" placeholder="请输入内容...">
            </div>
            <div class="form-group col-md-7" >
                <label>图片链接</label>
                <input type="text" id="img_url" class="form-control" placeholder="请输入图片链接...">
            </div>
            <div class="form-group col-md-7" >
                <label>内容链接</label>
                <input type="text" id="t_url" class="form-control layui-input" placeholder="请输入内容链接...">
            </div>
            <div class="form-group col-md-7" >
                <div id="btn_edit" class="btn btn-info btn-flat pull-right">保存</div>
            </div>
        </form>
    </div>
    <!-- /.box-body -->
    </section>
</div>
</body>
<script>
    function reselect(){
        var _val = $('#category').val();
        if(_val !== ''){
            $('#category2').removeAttr('disabled');
        }else{
            $('#category2').attr('disabled','disabled');
            $('#category2').val('');
        }
    }
    $(function(){
        reselect();
        changeselected();
        $('#category').click(function(){
            var _val = $(this).val();
            if(_val !== ''){
                $('#category2').removeAttr('disabled');
            }else{
                $('#category2').attr('disabled','disabled');
                $('#category2').val('');
            }
        })
        function changeselected() {
            var _id=  $("#category").val();
            $.ajax({
                type: 'post',
                cache: false,
                url: '{:url("admin/Tencent/getCategoryList")}',
                data: {id: _id},
                success: function(data) {
                    if (data.code == "0") {
                        $("#category2 option").remove();
                        $.each(data.info, function (index, item) {
                            var html = '<option value="' + item.id + '">' + item.categoryname + '</option>';
                            $("#category2").append(html);
                        });
                    }
                }
            });
        }
        $('#category').change(function(){
            changeselected();
        })
        $('#btn_edit').click(function(){
            var _mid = $('#mid').val();
            var _category = $('#category').val();
            var _category2 = $('#category2').val();
            var _title = $('#title').val();
            var _desc = $('#desc').val();
            var imgurl  = $('#img_url').val();
            var _t_url = $('#t_url').val();
            if(_category == '' || _category2 == ''){
                layerAlert('请选择分类');
                return false;
            }
            if(_title == ''){
                layerAlert('请输入标题');
                return false;
            }
            if(imgurl == ''){
                layerAlert('请输入图片链接');
                return false;
            }
            if(_t_url == ''){
                layerAlert('请输入内容链接');
                return false;
            }
            $.ajax({
                type:'post',
                cache: false,
                url:"{:url('admin/replymessage/doEditReply')}",
                data:{id:_mid,category:_category,title:_title,category2:_category2,desc:_desc,t_url:_t_url,img_url:imgurl},
                success:function(data){
                    if(data.code==0){
                        layerAlert('添加成功',function(){
                            parent.relist();
                            layerParentClose();
                        });
                    }else{
                        layerAlert('添加失败');
                    }
                }
            })
        })
    })
</script>
</html>